<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
cfc('core')->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
$return=array();
if($_RQ['op']=='get'){
	$log=$this->pdo_get('log',array('mid'=>$_SESSION['uid'],'passed'=>3));
	if($log['id']){
		$return['passed']=$this->model('member')->check_passed($log);
		if($return['passed']){
			if($_SESSION['container']=='baiduapp' || $_SESSION['container']=='aliapp' || $_SESSION['container']=='ttapp' || $_SESSION['container']=='wxapp'){
				exi($return);
			}elseif($log['backurl']){
				exi('','',$log['backurl']);
			}
		}
	}
	$item=pdo_get('core_members',array('id'=>$_SESSION['uid']),array('username','nickname','isrealname','realname','mobile','realmobile','cardnum','cardinfo'));
	$item['nickname']=$item['nickname']?:$item['username'];
	$item['cardinfo']=json_decode($item['cardinfo'],true);
	$item['image']=$item['cardinfo']['image'];
	$item['backimage']=$item['cardinfo']['backimage'];
	if($item['isrealname']){
		$item['realname']=$item['realname']?cfc('tools')->substr($item['realname'],0,1).'**':'';
		$item['cardnum']=$item['cardnum']?cfc('tools')->substr($item['cardnum'],0,5).'**********':'';
		$tips='您已通过实名认证，无需重复认证！';
	}else{
		$tips='请提交真实姓名，身份证号码！以备顺利完成实名认证！';
		$log=$this->pdo_get('log',array('mid'=>$_SESSION['uid'],'passed'=>0));
		/*if($log['id']){
			$postdata=array(
				"certifyid" => $log['certifyid'],
				"ordersn" => $log['ordersn'],
			);
			$passed=$this->model('member')->check_passed($postdata);
			if(!$passed){
				$item['ispost']=1;
				$tips='您已提交认证，无需重复提交！请等到审核！';
			}
		}*/
	}
	$return['item']=$item;
	$return['tips']=$tips;
	set_html('title','实名认证');
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$postdata['user_name']=$postdata['realname'];
	$postdata['cert_no']=$postdata['cardnum'];
	$postdata['ordersn']='SN'.get_ordersn($this->tablename('log'),'ordersn');
	$postdata['cardinfo']['image']=$postdata['image'];
	$postdata['cardinfo']['backimage']=$postdata['backimage'];
	if(!$postdata['user_name'] || !$postdata['cert_no']){
		exi('姓名，身份证号必填！','error');
	}
	$logid=$this->model('member')->addlog($postdata);
	$postdata['id']=$postdata['logid']=$logid;
	$res=$this->model('model')->person_check($postdata);
	if($res['certifyId']){
		$postdata['certifyid']=$res['certifyId'];
		$postdata['certifyurl']=$res['certifyUrl'];
		$this->pdo_update('log',array('certifyid'=>$postdata['certifyid'],'certifyurl'=>$postdata['certifyurl']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$logid));
		if($_SESSION['container']=='baiduapp' || $_SESSION['container']=='aliapp' || $_SESSION['container']=='ttapp' || $_SESSION['container']=='wxapp'){
			$postdata['backurl']=$_SESSION['backurl'];
			exi($postdata);
		}else{
			exi('','',$res['certifyUrl']);
		}
	}
	exi('提交成功！','','goback');
}
if($_RQ['op']=='isshibie'){
	//成功进入人脸识别页面，
	$logid=$_RQ['logid'];
	$this->model('member')->isshibie($logid);
	exi('success');
}
if($_RQ['op']=='uppassed'){
	$log=get_postdata();
	$this->model('member')->uppassed($log);
	exi('认证成功.');
}
if($_RQ['op']=='backurl'){
	$logid=$_RQ['logid'];
	$log=$this->pdo_get('log',array('id'=>$logid));
	$this->model('member')->uppassed($log);
	if($_SESSION['container']=='baiduapp' || $_SESSION['container']=='aliapp' || $_SESSION['container']=='ttapp' || $_SESSION['container']=='wxapp'){
		exi('认证成功.');
	}else{
		exi('认证成功.','',$log['backurl']);
	}
}